﻿JSLoad("js/jquery-1.6.js");
JSLoad("js/template.js");

function setDefault(obj,value){
	if(obj.value==""){
		obj.value= value;
		obj.style.color ="#b3b3b3";
	}else if(obj.value == value){
		obj.style.color ="#b3b3b3";
	}else{
		obj.style.color ="#000000";
	}
}

function cleanDefault(obj,value){
	if(obj.value==value){
		obj.value= "";
		obj.style.color ="#000000";
	}
}
window.onload=data_supervises;
var max_NO= 15;
var path= "";
var httpath = "http://192.168.1.5:8080/in_cms/";
function data_supervises() {
	//解开火狐等浏览器的中文编码
	$("#person").val("");
	$("#state").val("");
	$("#dep").val("");
	$("#title").val("事件名称关键字");
	 var check_array=document.getElementsByName("selAll");    
     for(var i=0;i<check_array.length;i++) {
          check_array[i].checked=false;        
         } 
	$.getJSON(httpath+"supervise.do?method=getList&callback=?", {
		pageNo : 1,
		maxNo : max_NO,
		timestamp : new Date().getTime(), // 日期戳记参数，防止缓存
		username : encodeURI("中文")
	}, function(data) {
		if (data != null) {
			var data_new = [];
			data_new['newslists'] = data.content_list;
		
			var result = TrimPath.processDOMTemplate("news_template",data_new);
		   $("#news_list").html(result);
			var countpage = Math.ceil(data.total /max_NO);
			if (countpage > 0) {
				r = page_news(1, countpage, 'javascript:search_news(.page.)',true,data.total);
				document.getElementById("turnPage_news").innerHTML = r;
			}else{
				document.getElementById("turnPage_news").innerHTML = "";
			}
			 
			 var check_sel=document.getElementsByName("sel");    
		      for(var i=0;i<check_sel.length;i++) {
		    	
		           check_sel[i].checked=false;     
		       } 
		      
		}
	});
}

var orderNum;
var thisSyllable;
function supervises_like_list(order,syllable) {
	//解开火狐等浏览器的中文编码
	orderNum=order;
	if(order=="-1"){
		 $("#"+syllable+"_-1").show();
		 $("#"+syllable+"_1").hide();
		}else{
			 $("#"+syllable+"_1").show();
			 $("#"+syllable+"_-1").hide();
		}
	 $("#"+thisSyllable+"_1").show();
	 $("#"+thisSyllable+"_-1").hide();
	thisSyllable=syllable;
	
	 var check_array=document.getElementsByName("selAll");    
     for(var i=0;i<check_array.length;i++) {
          check_array[i].checked=false;        
         } 
     var department=$("#dep").val();
     var repName=$("#person").val();
    
     var title=$("#title").val();
    if(title=="事件名称关键字"){
      title="";
    }
    if(department=="输入部门名称"){
    	department="";
      }
    if(repName=="请选择"){
    	repName="";
      }
     var state=$("#state").val();
     var sendDate=$("#sendDate").val();
     var repDate=$("#repDate").val();
	$.getJSON(httpath+"supervise.do?method=getListLike&callback=?", {
		pageNo : 1,
		maxNo : max_NO,
		syllable:encodeURI(syllable,"UTF-8"),
		department:encodeURI(department,"UTF-8"),
		repName:encodeURI(repName,"UTF-8"),
		title:encodeURI(title,"UTF-8"),
		state:encodeURI(state,"UTF-8"),
		order:encodeURI(order,"UTF-8"),
		sendDate:encodeURI(sendDate,"UTF-8"),
		repDate:encodeURI(repDate,"UTF-8"),
		timestamp : new Date().getTime(), // 日期戳记参数，防止缓存
		username : encodeURI("中文")
	}, function(data) {
		if (data != null) {
			var data_new = [];
			data_new['newslists'] = data.content_list;
		
			var result = TrimPath.processDOMTemplate("news_template",data_new);
		
		   $("#news_list").html(result);
			var countpage = Math.ceil(data.total /max_NO);
			
			if (countpage > 0) {
				r = page_supervise(1, countpage, 'javascript:search_supervise(.page.)',true,data.total);
				document.getElementById("turnPage_news").innerHTML = r;
			}else{
				document.getElementById("turnPage_news").innerHTML = "";
			}
			  
			 var check_sel=document.getElementsByName("sel");    
		      for(var i=0;i<check_sel.length;i++) {
		    	
		           check_sel[i].checked=false;     
		       } 
		      
		}
	});
}

function search_news(pageNum) {
	
	try {
		$.getJSON(httpath+"supervise.do?method=getList&callback=?", {
		pageNo : pageNum,
		maxNo : max_NO,
		timestamp : new Date().getTime(), // 日期戳记参数，防止缓存
		username : encodeURI("中文")
		}, function(data) {
			if (data != null) {
				var data_new = [];
				data_new['newslists'] = data.content_list;
				
				var result = TrimPath.processDOMTemplate("news_template",data_new);
				 $("#news_list").html(result);
				var countpage = Math.ceil(data.total /max_NO);
				if (countpage > 0) {
					r = page_news(pageNum, countpage, 'javascript:search_news(.page.)',true,data.total);
					document.getElementById("turnPage_news").innerHTML = r;
				}else{
					document.getElementById("turnPage_news").innerHTML = "";
				}
			}
		});

	} catch (e) {

		alert("查询服务器维护，请稍后再试！" + e);
	}

}

function page_news(curPage, countPage, para, f_e,totalProperty) {
	if (f_e == 'undefined') {
		f_e = false;
	}
	curPage = curPage < 1 ? 1 : (curPage > countPage ? countPage: (curPage || 1));
	var pa = [];
	if (countPage > 1 && f_e) {
		if (curPage == 1) {
			pa.push('<span class="page-start">上页</span>');
		} else {
			var pagePrev=curPage-1;			
			pa.push('<a href="javascript:search_news('+pagePrev+')" >上页</a>');
			if(curPage >4){
				if(curPage !=5 && countPage == 5){
					pa.push('<span><a href="javascript:search_news(1)" >1</a>...</span>');	
				}
				if(curPage >=5 && countPage > 6){
					pa.push('<span><a href="javascript:search_news(1)" >1</a>...</span>');	
				}
				
			}else if(curPage ==2){
				pa.push('<span><a href="javascript:search_news(1)" >1</a></span>');	
			}else if(curPage ==4 && countPage > 6){
				pa.push('<span><a href="javascript:search_news(1)" >1</a></span>');	
			}	
		}
	}
	
	
	if (curPage < 3) {
		pa.push('<span class="page-cur">' + curPage + '</span>');
		page_deal(pa, para, '<a href="{para}">{page}</a>', curPage + 1, countPage < 6 ? countPage + 1 : 6);
	} else {
		if(curPage >= 3 && countPage == 5){
			var end = curPage + 3 < countPage ? curPage + 3 : countPage;
			page_deal(pa, para, '<a href="{para}">{page}</a>', end - 4 < 0 ? 1 : end - 4, curPage);
			pa.push('<span class="page-cur">' + curPage + '</span>');
			page_deal(pa, para, '<a href="{para}">{page}</a>', curPage + 1, end);
		}else{
			var end = curPage + 3 < countPage ? curPage + 3 : countPage;
			page_deal(pa, para, '<a href="{para}">{page}</a>', end - 5 < 0 ? 1 : end - 5, curPage);
			pa.push('<span class="page-cur">' + curPage + '</span>');
			page_deal(pa, para, '<a href="{para}">{page}</a>', curPage + 1, end);
		}
		
	}
	if (countPage > 1 && f_e) {
		if (curPage == countPage) {
		} else {
            if (curPage <= countPage - 4 ) {
            	pa.push('...<a href="javascript:search_news(' + countPage + ')">'+countPage+'</a>');
			}else{
				if(countPage != 2 && countPage != 3 && countPage != 4 && countPage != 5){
					pa.push('<a href="javascript:search_news(' + countPage + ')">'+countPage+'</a>');
				}
				if(curPage == 3 && countPage == 4){
					pa.push('<a href="javascript:search_news(' + countPage + ')">'+countPage+'</a>');
				}
				if(curPage == 3 && countPage == 5){
					pa.push('<a href="javascript:search_news(' + countPage + ')">'+countPage+'</a>');
				}
				if(curPage == 4 && countPage == 5){
					pa.push('<a href="javascript:search_news(' + countPage + ')">'+countPage+'</a>');
				}
				
			}
		}
	}
	
   var pageNext=curPage+1;
	if(curPage < countPage){
		pa.push('<a href="javascript:search_news('+pageNext+')" >下页</a>');
	}else if(pageNext>=countPage && countPage != 1){
		pa.push('<span class="page-start">下页</span>');
	}
    pa.push(' 共'+countPage+'页');
	pa.push(' 共'+totalProperty+'条');
	return pa.join('');
}

function search_supervise(pageNum) {
	
	var check_array=document.getElementsByName("selAll");    
     for(var i=0;i<check_array.length;i++) {
          check_array[i].checked=false;        
         } 
     var department=$("#dep").val();
     var repName=$("#person").val();
     var title=$("#title").val();
    if(title=="事件名称关键字"){
      title="";
    }
    if(department=="输入部门名称"){
    	department="";
      }
    if(repName=="接收人"){
    	repName="";
      }
     var state=$("#state").val();
     var sendDate=$("#sendDate").val();
     var repDate=$("#repDate").val();
	try {
		$.getJSON(httpath+"supervise.do?method=getListLike&callback=?", {
		pageNo : pageNum,
		maxNo : max_NO,
		department:encodeURI(department,"UTF-8"),
		syllable:encodeURI(thisSyllable,"UTF-8"),
		repName:encodeURI(repName,"UTF-8"),
		title:encodeURI(title,"UTF-8"),
		state:encodeURI(state,"UTF-8"),
		order:encodeURI(orderNum,"UTF-8"),
		sendDate:encodeURI(sendDate,"UTF-8"),
		repDate:encodeURI(repDate,"UTF-8"),
		timestamp : new Date().getTime(), // 日期戳记参数，防止缓存
		username : encodeURI("中文")
		}, function(data) {
			if (data != null) {
				var data_new = [];
				data_new['newslists'] = data.content_list;
				
				var result = TrimPath.processDOMTemplate("news_template",data_new);
				 $("#news_list").html(result);
				var countpage = Math.ceil(data.total /max_NO);
				if (countpage > 0) {
					r = page_supervise(pageNum, countpage, 'javascript:search_supervise(.page.)',true,data.total);
					document.getElementById("turnPage_news").innerHTML = r;
				}else{
						document.getElementById("turnPage_news").innerHTML = "";
				}
			}
		});

	} catch (e) {

		alert("查询服务器维护，请稍后再试！" + e);
	}

}

function page_supervise(curPage, countPage, para, f_e,totalProperty) {
	if (f_e == 'undefined') {
		f_e = false;
	}
	curPage = curPage < 1 ? 1 : (curPage > countPage ? countPage: (curPage || 1));
	var pa = [];
	if (countPage > 1 && f_e) {
		if (curPage == 1) {
			pa.push('<span class="page-start">上页</span>');
		} else {
			var pagePrev=curPage-1;			
			pa.push('<a href="javascript:search_supervise('+pagePrev+')" >上页</a>');
			if(curPage >4){
				if(curPage !=5 && countPage == 5){
					pa.push('<span><a href="javascript:search_supervise(1)" >1</a>...</span>');	
				}
				if(curPage >=5 && countPage > 6){
					pa.push('<span><a href="javascript:search_supervise(1)" >1</a>...</span>');	
				}
				
			}else if(curPage ==2){
				pa.push('<span><a href="javascript:search_supervise(1)" >1</a></span>');	
			}else if(curPage ==4 && countPage > 6){
				pa.push('<span><a href="javascript:search_supervise(1)" >1</a></span>');	
			}	
		}
	}
	
	
	if (curPage < 3) {
		pa.push('<span class="page-cur">' + curPage + '</span>');
		page_deal(pa, para, '<a href="{para}">{page}</a>', curPage + 1, countPage < 6 ? countPage + 1 : 6);
	} else {
		if(curPage >= 3 && countPage == 5){
			var end = curPage + 3 < countPage ? curPage + 3 : countPage;
			page_deal(pa, para, '<a href="{para}">{page}</a>', end - 4 < 0 ? 1 : end - 4, curPage);
			pa.push('<span class="page-cur">' + curPage + '</span>');
			page_deal(pa, para, '<a href="{para}">{page}</a>', curPage + 1, end);
		}else{
			var end = curPage + 3 < countPage ? curPage + 3 : countPage;
			page_deal(pa, para, '<a href="{para}">{page}</a>', end - 5 < 0 ? 1 : end - 5, curPage);
			pa.push('<span class="page-cur">' + curPage + '</span>');
			page_deal(pa, para, '<a href="{para}">{page}</a>', curPage + 1, end);
		}
		
	}
	if (countPage > 1 && f_e) {
		if (curPage == countPage) {
		} else {
            if (curPage <= countPage - 4 ) {
            	pa.push('...<a href="javascript:search_supervise(' + countPage + ')">'+countPage+'</a>');
			}else{
				if(countPage != 2 && countPage != 3 && countPage != 4 && countPage != 5){
					pa.push('<a href="javascript:search_supervise(' + countPage + ')">'+countPage+'</a>');
				}
				if(curPage == 3 && countPage == 4){
					pa.push('<a href="javascript:search_supervise(' + countPage + ')">'+countPage+'</a>');
				}
				if(curPage == 3 && countPage == 5){
					pa.push('<a href="javascript:search_supervise(' + countPage + ')">'+countPage+'</a>');
				}
				if(curPage == 4 && countPage == 5){
					pa.push('<a href="javascript:search_supervise(' + countPage + ')">'+countPage+'</a>');
				}
				
			}
		}
	}
	
   var pageNext=curPage+1;
	if(curPage < countPage){
		pa.push('<a href="javascript:search_supervise('+pageNext+')" >下页</a>');
	}else if(pageNext>=countPage && countPage != 1){
		pa.push('<span class="page-start">下页</span>');
	}
    pa.push(' 共'+countPage+'页');
	pa.push(' 共'+totalProperty+'条');
	return pa.join('');
}

function page_deal(a, b, c, d, e) {
	e = e || d + 1;
	for (; d < e; d++) {
		a.push(c.replace(/\{para\}/g, url_set(b, d)).replace(/\{page\}/g, d));
	}
}

function url_set(url, v) {
	url = url.replace(/\.page\./, v);
	return url;
}

function JSLoad(url, container, type, defer, language, title) {
	if (container == undefined || container == null)
		container = this; // setup container
	if (typeof container.write == "undefined")
		if (typeof container.document != "undefined")
			container = container.document;
		else
			throw "Invalid container. Unable to load [" + url + "]"; // no
																		// type
																		// set
	if (type == undefined || type == null) {
		type = ''; // no language so set default type
		if (language == undefined || language == null) {
			language = undefined;
			type = "text/javascript";
		}
	} // set default language
	if (language == undefined || language == null)
		language = "JavaScript"; // set title
	if (title == undefined || title == null)
		title = ''; // set defer
	if (defer == undefined)
		defer = false; // build the script object
	var script = container.createElement("script");
	script.defer = defer;
	script.language = language;
	script.title = title;
	script.type = type;
	script.src = url; // dynamically load the script via it's container
	var head = container.getElementsByTagName("head")[0];
	head.appendChild(script);
}

function JSPackage(packageID, owner) {
	var _package = (owner == undefined || owner == null) ? window : owner;
	packageID = packageID.split('.');
	for ( var i = 0, j = packageID.length; i < j; i++)
		if (typeof _package[packageID[i]] == "undefined")
			_package = _package[packageID[i]] = {};
		else
			_package = _package[packageID[i]];
	CompleteImports(owner);
	return _package;
}

function JSPackageException(packageID) {
	this.name = _pathPacked + ".JSPackageException";
	this.message = "Invalid package name [" + packageID + "]";
	this.toString = function() {
		return "[" + this.name + "] :: " + this.message;
	};
}

function gLtrim(str) {
	str = str + "";
	for ( var i = 0; (i < str.length) && (str.charAt(i) == " "); i++)
		;
	return str.substring(i, str.length);
}

function gRtrim(str) {
	str = str + "";
	for ( var i = str.length - 1; (i >= 0) && (str.charAt(i) == " "); i--)
		;
	return str.substring(0, i + 1);
}

function gTrim(str) {
	return gRtrim(gLtrim(str));
}

var getHost = function(url) {
	var host = "null";
	if (typeof url == "undefined" || null == url) {
		url = window.location.href;
	}
	var regex = /.*\:\/\/([^\/]*).*/;
	var match = url.match(regex);
	if (typeof match != "undefined" && null != match) {
		host = match[1];
	}
	return host;
}


